package com.swak.frame.support;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.CollectionUtils;

import com.swak.frame.filter.ApiFilter;

public class ServiceConfigurerComposite implements SwakServiceConfigurer {

    private final List<SwakServiceConfigurer> delegates = new ArrayList<>();

    public void addSwakServiceConfigurer(List<SwakServiceConfigurer> configurers) {
        if (!CollectionUtils.isEmpty(configurers)) {
            this.delegates.addAll(configurers);
        }
    }

    @Override
    public void configureFilterHandler(ConfigPipeline<ApiFilter> pipelineBuilder) {
        for (SwakServiceConfigurer delegate : this.delegates) {
            delegate.configureFilterHandler(pipelineBuilder);
        }
    }

    @Override
    public void extendConfigureFilters(ConfigPipeline<ApiFilter> pipelineBuilder) {
        for (SwakServiceConfigurer delegate : this.delegates) {
            delegate.extendConfigureFilters(pipelineBuilder);
        }
    }
}
